home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / net / AMarquee1_43.lha / AMarquee / examples / RemoveTest.c < prev    next >
C/C++ Source or Header  |  1997-04-28  |  3KB  |  93 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <clib/AMarquee_protos.h>
  11.  
  12. #include <pragmas/AMarquee_pragmas.h>
  13.  
  14. struct Library * AMarqueeBase = NULL;
  15. struct QSession * session     = NULL;
  16.  
  17. void CleanExit(void)
  18. {
  19.   if (session)      QFreeSession(session);       /* This MUST be done before we close the library! */
  20.   if (AMarqueeBase) CloseLibrary(AMarqueeBase);
  21.   printf("All done.\n");
  22. }
  23.  
  24. /* Main program--simply increments our counter whenever someone else increments theirs */
  25. int main(int argc, char ** argv)
  26. {
  27.   char * connectTo, * progName;
  28.   int port = 2957;
  29.   BOOL BPut = FALSE;
  30.   BOOL BDie = FALSE;
  31.   
  32.   atexit(CleanExit);
  33.     
  34.   printf("Usage:  RemoveTest [hostname=localhost] [name=removetest]\n");
  35.  
  36.   connectTo = (argc>1) ? argv[1] : "localhost";
  37.   progName  = (argc>2) ? argv[2] : "removetest";
  38.  
  39.   if ((AMarqueeBase = OpenLibrary("amarquee.library",37L)) == NULL)
  40.   {
  41.     printf("Couldn't open amarquee.library v37!\n");
  42.     exit(RETURN_ERROR);
  43.   }
  44.   
  45.   printf("connecting to %s:%i...\n",connectTo, port);
  46.   if ((session = QNewSession(connectTo, port, progName)) == NULL)
  47.   {
  48.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  49.     CloseLibrary(AMarqueeBase);
  50.     exit(RETURN_WARN);
  51.   }
  52.   
  53.   printf("RemoveTest connected to server %s:%i\n",connectTo, port);
  54.  
  55.   /* Setup */
  56.   (void)QSetOp(session, "switch", "", 1L);
  57.   (void)QGo(session,QGOF_SYNC);
  58.  
  59.   while(BDie == FALSE)
  60.   {
  61.     struct QMessage * qMsg;
  62.     ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C);
  63.  
  64.     /* Wait for next message from the server */
  65.     signals = Wait(signals);
  66.     
  67.     if (signals & (1L << session->qMsgPort->mp_SigBit))
  68.     {
  69.       while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
  70.       {
  71.         if (qMsg->qm_Status != QERROR_NO_ERROR) 
  72.         {
  73.           printf("Error %i detected!\n", qMsg->qm_Status);
  74.           BDie = TRUE;
  75.         }
  76.         else
  77.         {
  78.           /* It must be the sync signal, meaning everyone else has seen our update */    
  79.           printf("Synced, now %s switch...\n", BPut ? "setting" : "removing"); 
  80.  
  81.           if (BPut) (void) QSetOp(session, "switch", "", 1L);
  82.                else (void) QDeleteOp(session, "switch");
  83.           (void) QGo(session,QGOF_SYNC);
  84.           
  85.           if (BPut) BPut = FALSE; else BPut = TRUE;
  86.         }
  87.         FreeQMessage(session,qMsg);
  88.       }
  89.     }
  90.     if (signals & SIGBREAKF_CTRL_C) BDie = TRUE;  /* Quit if CTRL-C pressed */
  91.   }
  92. }
  93.